<html>
<head><meta charset="utf-8"><title>Unit tests in rustc · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Unit.20tests.20in.20rustc.html">Unit tests in rustc</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="237059886"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Unit%20tests%20in%20rustc/near/237059886" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Sniadek <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Unit.20tests.20in.20rustc.html#237059886">(May 02 2021 at 15:11)</a>:</h4>
<p>Hello everyone!<br>
I'm working on a toy language in Rust and I dig in rustc for inspirations and to gain some knowledge on how production scale programming languages work. <br>
I familiarized myself with <a href="https://rustc-dev-guide.rust-lang.org/tests/intro.html">https://rustc-dev-guide.rust-lang.org/tests/intro.html</a> but I noticed that e.g rustc_parse doesn't have any unit tests. Are those just not worth the time and effort since the parser has lots of session dependencies that would be time-consuming to mock? When are unit tests preferred?<br>
Newbie compiler tinkerer looking for some advices :)<br>
Thank you!</p>



<a name="237060254"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Unit%20tests%20in%20rustc/near/237060254" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Unit.20tests.20in.20rustc.html#237060254">(May 02 2021 at 15:19)</a>:</h4>
<p>Honestly I think the answer is "because our build system makes running them painful"<br>
<a href="https://github.com/rust-lang/rust/issues/51748">https://github.com/rust-lang/rust/issues/51748</a></p>



<a name="237060360"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Unit%20tests%20in%20rustc/near/237060360" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Unit.20tests.20in.20rustc.html#237060360">(May 02 2021 at 15:20)</a>:</h4>
<p>And it requires organizing the code so that it <em>can</em> be unit tested</p>



<a name="248676830"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Unit%20tests%20in%20rustc/near/248676830" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oliver <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Unit.20tests.20in.20rustc.html#248676830">(Aug 06 2021 at 22:41)</a>:</h4>
<p>afaik there is also no simple way of getting debug logging in unit tests</p>



<a name="248707444"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Unit%20tests%20in%20rustc/near/248707444" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Unit.20tests.20in.20rustc.html#248707444">(Aug 07 2021 at 09:42)</a>:</h4>
<p><code>cargo test -- --nocapture</code> disables log supression</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>